package com.liuguang.redis.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

/**
 * @ClassName: RedisConfig
 * @Description：
 * @Author: wanghr
 * Date: 12:45 PM 2020/9/13
 * Version: 1.0
 */
@Configuration
public class RedisConfig {
    @Autowired
    private RedisTemplate redisTemplate;


    @Bean
    public RedisTemplate getRedisTemplate() {

        RedisSerializer stringRedisSerializer = redisTemplate.getStringSerializer();
//        FastJsonRedisSerializer<User> fastJsonRedisSerializer = new FastJsonRedisSerializer<User>(User.class);
//        FastJsonRedisSerializer<JSONObject> fastJsonRedisSerializer = new FastJsonRedisSerializer<JSONObject>(JSONObject.class);
        //设置 redis 键和value 的序列化类型
        redisTemplate.setKeySerializer(stringRedisSerializer);
        redisTemplate.setValueSerializer(stringRedisSerializer);
        return redisTemplate;
    }
}
